package com.peak.distribution.entity.agent;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;

import com.peak.distribution.entity.order.DisOrder;
import com.peak.distribution.enums.AwardType;
import com.peak.distribution.enums.Constants;
import com.peak.spring.boot.api.entity.DefaultStategyEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Entity
@Table(name = "dis_agent_award_log")
@Data
@EqualsAndHashCode(callSuper=true)
public class DisAgentAwardLog extends DefaultStategyEntity {

	private static final long serialVersionUID = Constants.DISTRIBUTION_VERSION;
	
	/** 到账账户 */
	private DisAgentAccount account;
	
	/** 奖金 */
	private DisAgentAward award;
	
	/** 奖金类型 */
	private AwardType type;
	
	/** 奖励时间 */
	private Date awardTime;
	
	/** 奖励金额 */
	private Integer awardAmount;
	
	/** 源自的订单 */
	private DisOrder order;
	
	/** 签名 */
	private String sign;

	@ManyToOne
	@JoinColumn(name = "account_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisAgentAccount getAccount() {
		return account;
	}

	@ManyToOne
	@JoinColumn(name = "agent_award_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisAgentAward getAward() {
		return award;
	}

	@ManyToOne
	@JoinColumn(name = "order_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisOrder getOrder() {
		return order;
	}

	@Enumerated(EnumType.STRING)
	public AwardType getType() {
		return type;
	}

	@Transient
	public String getSignSource() {
		return this.id + this.type.name() + this.awardTime.getTime() + this.awardAmount;
	}
}
